home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1996
/
MacHack 1996.toast
/
Hacks
/
Hacks ’92
/
Text Capture FKEY
/
Copy text.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-06-12
|
2KB
|
93 lines
#include "Copy text.h"
#include "defs.h"
#include <Script.h>
static void Insert_text( short byteCnt, Ptr textAddr );
void Copy_all_text( short byteCnt, Ptr textAddr )
{
Insert_text( byteCnt, textAddr );
}
void Copy_window_text( short byteCnt, Ptr textAddr )
{
if ( PtInRect(front->pnLoc, &front->portRect) )
{
Insert_text( byteCnt, textAddr );
}
}
void Copy_selected_text( short byteCnt, Ptr textAddr )
{
short first_offset, last_offset;
short widths[500];
register short i;
short pen_left;
if ( (front->pnLoc.v < selected_rect.top) ||
(front->pnLoc.v > selected_rect.bottom) )
return;
SetPort( front );
pen_left = front->pnLoc.h;
if (byteCnt < 500)
{
MeasureText( byteCnt, (char *)textAddr, widths );
i = 0;
while ( (i < byteCnt) && (pen_left + widths[i] < selected_rect.left) )
++i;
first_offset = i;
i = byteCnt;
while ( (i > 0) && (pen_left + widths[i] > selected_rect.right) )
--i;
last_offset = i;
}
else
{
first_offset = 0;
last_offset = byteCnt;
}
SetPort( text_port );
if (first_offset < last_offset)
{
Insert_text( last_offset - first_offset, textAddr + first_offset );
}
}
static void Insert_text( short byteCnt, Ptr textAddr )
{
short length;
TextStyle style_rec;
if (last_v == 0) // This is the first time text has been drawn
last_v = front->pnLoc.v;
else // Separate this text from previous text
{
if ( spaces || (front->pnLoc.v == last_v) )
TEKey( ' ', text_h );
else
{
TEKey( 0x0D /* return */, text_h );
last_v = front->pnLoc.v;
}
/* Make the space just inserted unstyled. */
length = (**text_h).teLength;
TESetSelect( length - 1, length, text_h );
style_rec.tsFace = 0;
TESetStyle( doFace, &style_rec, false, text_h );
TESetSelect( length, length, text_h );
}
TEInsert( textAddr, (long)byteCnt, text_h );
length = (**text_h).teLength;
TESetSelect( length - byteCnt, length, text_h );
style_rec.tsFont = front->txFont;
style_rec.tsFace = front->txFace;
style_rec.tsSize = front->txSize;
TESetStyle( doFont+doFace+doSize, &style_rec, false, text_h );
TESetSelect( length, length, text_h );
}